<!-- index -->
<template>
  <!-- <div> -->
  <el-card class="elCard" :body-style="{ padding: '15px 0 0 10px' }">
    <el-form :model="formData" label-width="100px" :inline="true" style="display: flex;">
      <el-form-item v-show="showNode" label="点位搜索" style="display: flex;">
        <el-input v-model="formData.nodeName" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item v-show="showNode" label="区域搜索" style="display: flex;">
        <el-select v-model="formData.regionId" clearable filterable placeholder="请选择">
          <el-option v-for="item in list" :key="item.id" :label="item.name" :value="item.id" />

        </el-select>
      </el-form-item>
      <el-form-item v-show="showPartner" label="合作商搜索" style="display: flex;">
        <el-input v-model="formData.partnerName" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item v-show="showRegion" label="区域搜索" style="display: flex;">
        <el-input v-model="formData.name" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item style="display: flex;">
        <el-button type="primary" size="medium" icon="el-icon-search" style="height: 39px" @click="searchFn">搜索</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- </div> -->
</template>

<script>
import { regionSearch } from '@/api'
export default {
  props: {
    showPartner: {
      type: Boolean,
      default: false
    },
    showNode: {
      type: Boolean,
      default: false
    },
    showRegion: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formData: {
        name: '',
        nodeName: '',
        regionId: '',
        partnerName: ''
      },
      list: []
    }
  },
  async created() {
    if (this.showNode) {
      const res = await regionSearch({
        pageIndex: 1,
        pageSize: 100000
      })
      // console.log(res)
      this.list = res.data.currentPageRecords
    }
  },
  methods: {
    searchFn() {
      if (this.showRegion) {
        this.$emit('searchFn', this.formData)
        return
      }
      if (this.showNode) {
        // console.log(this.formData)
        const obj = {
          name: this.formData.nodeName,
          regionId: this.formData.regionId
        }
        this.$emit('searchNode', obj)
        return
      }
      if (this.showPartner) {
        const obj = {
          name: this.formData.partnerName
        }
        this.$emit('searchPartner', obj)
        return
      }
    }
  }

}

</script>
<style lang='scss' scoped>
::v-deep .elCard {
  height: 100px;
  width: 1159px;
  padding: 0;
}
.el-card__body {
    padding: 0px;
}
</style>
